package com.app.mymusic.ui.persons;

import android.view.View;

import com.app.mymusic.R;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

/**
 * Created by Administrator on 2016-12-13.
 */

public class ExpandableItemAdapter extends BaseMultiItemQuickAdapter <MultiItemEntity, BaseViewHolder>{

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    public static final int TYPE_PERSON = 2;

    public ExpandableItemAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_1, R.layout.item_depart);
        addItemType(TYPE_LEVEL_0, R.layout.item_person);
    }

    @Override
    protected void convert(final BaseViewHolder baseViewHolder, MultiItemEntity item) {

        switch (baseViewHolder.getItemViewType()){
            case TYPE_LEVEL_0:
                final Person person= (Person) item;
                baseViewHolder.setText(R.id.person,person.name+":"+person.interest);
                break;
            case TYPE_LEVEL_1:
                final Depart depart= (Depart) item;
                baseViewHolder.setText(R.id.depart,depart.name+"--"+depart.beizhu);
                baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos=baseViewHolder.getAdapterPosition();
                        test(depart,pos);
                        if(depart.isExpanded()){
                            collapse(pos);
                        }else{
                            expand(pos);
                        }
                    }
                });
                break;
        }
    }

    private void test(Depart depart, int pos) {
    }
}
